package com.iwunu.gateway.service.impl;

import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.iwunu.gateway.entity.FLockLog;
import com.iwunu.gateway.service.CmdIssuedMongodbService;
import com.iwunu.gateway.service.FlockLogService;
import com.iwunu.iot.common.util.DateUtil;

@Component
public class FlockServiceImpl implements FlockLogService{
		@Resource
		private MongoTemplate mongoTemplate;
		@Autowired
		CmdIssuedMongodbService cmdIssuedMongodbService;
		@Override
		public void saveLog(String userId,String data,String clientId,Long lockId,Integer type,Integer role){
			try {
				cmdIssuedMongodbService.updateStatus(clientId);
			} catch (Exception e) {
				e.printStackTrace();
			}
			String uuid = UUID.randomUUID().toString().replace("-", "");
			FLockLog fl = new FLockLog();
			fl.setCreateTime(DateUtil.nowDateTime());
			fl.setData(data);
			fl.setClientId(lockId.toString());
			fl.setFlDeviceId(clientId);
			fl.setType(type);
			fl.setSerialNumber(uuid);
			fl.setPitNum(-1);
			fl.setUserId(userId);
			fl.setStatus(-1);
			fl.setRole(role);
			mongoTemplate.insert(fl);
		}
		@Override
		public void saveBleLog(String userId, String data, String clientId, Integer type, Integer role) {
			String uuid = UUID.randomUUID().toString().replace("-", "");
			FLockLog fl = new FLockLog();
			fl.setCreateTime(DateUtil.nowDateTime());
			fl.setData(data);
			fl.setClientId(clientId);
			fl.setFlDeviceId(clientId);
			fl.setType(type);
			fl.setSerialNumber(uuid);
			fl.setPitNum(-1);
			fl.setUserId(userId);
			fl.setStatus(0);
			fl.setRole(role);
			fl.setSucc(true);
			mongoTemplate.insert(fl);
			
		}
}
